<?php

    session_start();
    require_once("../includes/conn.php");
    require_once "../includes/wxtoken.php";

    $sysconfig=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."_sys_config where uid=1"));


    define('APPID',$sysconfig['cappid']);
    define('APPSECRET',$sysconfig['cappsecret']);
    $tools=new tools();
    if(!$tools->check_is_weixin())
    {
        echo '
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>入口不合法</title>
        </head>

        <body>
         错误：必须在微信环境下进入。
        </body>
        </html>
        ';
		exit;
    }

    $wxtoken = new wxtoken(1);

    $signPackage = $wxtoken->GetSignPackage();

   $ucode= $_SESSION['ucode']?$_SESSION['ucode']:'';
   if(isset($_GET['code']) &&$_GET['code']!=''&&$ucode=='')
    {
        $WXCODE=$_GET['code'];
        $getucodeurl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$WXCODE."&grant_type=authorization_code";
        $getucodejson=json_decode($tools->http_curl_get($getucodeurl,true));
        $wxlintoken=$getucodejson->access_token;
        $ucode=$getucodejson->openid;
        $getutxturl="https://api.weixin.qq.com/sns/userinfo?access_token=".$wxlintoken."&openid=".$ucode."&lang=zh_CN";
        $getutxtjson =json_decode($tools->http_curl_get($getutxturl,true));
        $uickname    =$getutxtjson->nickname;
        $usex        =intval($getutxtjson->sex);
        $headimgurl  =$getutxtjson->headimgurl;
        $nums=$dbconn->countn(DBQIAN."_user_list"," ucode='$ucode' and uid=1 ");
        if($nums==0){
            $times=time();
            $dbconn->noretquery("insert into ".DBQIAN."_user_list(ucode,uickname,usex,uheadimgurl,utime,uid)values
                     ('$ucode','$uickname',$usex,'$headimgurl',$times,1)");
        }

   }   
   elseif($ucode=='')
    {
        header("Location:index.php");exit();

    }
    $_SESSION['ucode']=$ucode;

    $score=isset($_GET['score'])?$_GET['score']:0; 

    $score_ar=str_split($score);


    foreach ($score_ar as $s_key => $s_value) {
      if($s_value==0)
        $s_value=10; 
       $html_score.='<img src="images/num'.$s_value.'.png" class="fl_img" />&nbsp;&nbsp;';
    }
    $max_score=$score;

    $data=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."_score where ucode='".$ucode."'"));
   if($score<intval($data['score']))
    {
       $max_score=intval($data['score']);
    }

    $score_mar=str_split($max_score);
    foreach ($score_mar as $sm_key => $sm_value) {
        if($sm_value==0)
           $sm_value=10; 
       $html_score_max.='<img src="images/num'.$sm_value.'.png" class="f2_img" />&nbsp;&nbsp;';
    }



  $utitle="我一口气接了".$max_score."个月饼，不来挑战，大奖就是我的啦!";
  $utitle_ct="中秋送礼，现金大奖等你拿";
    echo '

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="prefetch" href="images/p20.png" /> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />	
 <meta name="viewport" content="width=device-width,maximum-scale=1.0,user-scalable=no"/>
<title>接月饼成绩</title>
 <script src="lib/jquery-1.11.0.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
      wx.config({   
        debug: false,
        appId: \'';echo $signPackage["appId"];;echo '\',
        timestamp: ';echo $signPackage["timestamp"];;echo ',
        nonceStr: \'';echo $signPackage["nonceStr"];;echo '\',
        signature: \'';echo $signPackage["signature"];;echo '\',
        jsApiList: [
            \'checkJsApi\',
            \'onMenuShareTimeline\',
            \'onMenuShareAppMessage\',
            \'onMenuShareQQ\',
            \'onMenuShareWeibo\',
            \'hideMenuItems\',
            \'showMenuItems\',
            \'hideAllNonBaseMenuItem\',
            \'showAllNonBaseMenuItem\',
            \'translateVoice\',
            \'startRecord\',
            \'stopRecord\',
            \'onRecordEnd\',
            \'playVoice\',
            \'pauseVoice\',
            \'stopVoice\',
            \'uploadVoice\',
            \'downloadVoice\',
            \'chooseImage\',
            \'previewImage\',
            \'uploadImage\',
            \'downloadImage\',
            \'getNetworkType\',
            \'openLocation\',
            \'getLocation\',
            \'hideOptionMenu\',
            \'showOptionMenu\',
            \'closeWindow\',
            \'scanQRCode\',
            \'chooseWXPay\',
            \'openProductSpecificView\',
            \'addCard\',
            \'chooseCard\',
            \'openCard\'
        ]
      });
      wx.checkJsApi({
          jsApiList: [
            \'getNetworkType\',
            \'previewImage\'
          ],
          success: function (res) {
            alert(JSON.stringify(res));
          }
      });
      wx.ready(function () {
        wx.onMenuShareTimeline({
             title: "';echo $utitle;;echo '",
             link: "';echo WEBNAME."main/index.php?utocode=".$ucode;;echo '",
             imgUrl: "';
    echo WEBNAME."main/images/order_gx.jpg";;echo '",
             trigger: function (res) {
             },
             success: function (res) {       
             },
             cancel: function (res) {            
             },
             fail: function (res) {
             }
        });
        wx.onMenuShareAppMessage({
            title: "';echo  $utitle;;echo '",
            desc: "';echo  $utitle_ct;;echo '",
            link: "';echo WEBNAME."main/index.php?utocode=".$ucode;;echo '",
            imgUrl: "';
    echo WEBNAME."main/images/order_gx.jpg";;echo '",
            trigger: function (res) {
            },
            success: function (res) {
            },
            cancel: function (res) {
            },
            fail: function (res) {
            }
         });
    });
    </script>

<style>
body{margin:0px; padding:0px; font-size:16px; font-family:"Microsoft YaHei" ! important;}
ul{ list-style:none;}
.ucontent{ width:100%;}
.div_c1{ padding:30px; margin:0 auto;height:40px; line-height:40px; text-align:center;color:#fff;}
.div_c1 ul{margin:0px; padding:0px; text-align:center; }
.div_c1 li{ display:inline;height:40px; line-height:40px;vertical-align:middle; }
.div_c2{text-align:center;padding-top:40px; color:#dcb870; letter-spacing:1px;font-size:20px;font-weight:600;}

.div_c3{text-align:center;padding-top:12px; color:#fff;height:30px; line-height:30px;}
.div_c5{text-align:center;padding-top:5px; color:#fff;height:20px; line-height:20px; vertical-align:middle;}
.div_c4{clear:both;text-align:center;width:100%; margin:0 auto; }

.font1{color:#fff;}
.font2{color:#fff;font-size:30px;}
.l1{ width:30%;padding-left:20%; float:left; }
.l2{ width:30%; float:right;padding-right:20%;  }

.fl_img{width:40px;}
.f2_img{width:20px;}

 #mcover {position:fixed;top:0;left:0;width:100%;height:100%;background-color: rgba(0,0,0,0.7);z-index:20000; display:none}
 #mcover img {position:fixed;right:18px;top:5px;width:260px!important;height:260px!important;z-index:20001;}

</style>
</head>

<body>
<div id="mcover" onClick="this.style.display=\'none\'"><img src="images/fenxiang.png" /></div>
<div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">    
<img src="images/p20.png" height="100%" width="100%"/>    
</div>

<div class="ucontent">
<div class="div_c5">
<img src="images/p2.png" height="150px" width="150px"/>    
</div>
    <div class="div_c1">
    <ul>
    <li>'.$html_score.'</li>
    </ul>
    
    </div>
    <div class="div_c2">
    你的最高纪录是&nbsp;&nbsp;<span class="font1">'.$html_score_max.'</span>&nbsp;&nbsp;枚月饼
    <div style="margin-top:10px;"></div>
    长按二维码领取奖品
    </div>

     <div class="div_c4">
    <div style="padding:10px 0px;"></div>
    <img src="images/code.png"  width="53%"  />
    
    </div>

    <div class="div_c3">
    <div class="l1" onClick="location.href=\'insert_user.php\'">
    <img  src="images/sign2.png" width="30px" />
    <div style="margin-top:10px;" >再试一次</div>
    </div>
    <div class="l2" onclick="showMoon()">
    <img  src="images/sign1.png" width="40px" />
    <div  style="margin-top:10px;" >分享加分</div>
    </div>
    </div>
    
   

</div>
</body>
<script>
if(window.orientation!=0){
        var obj=document.getElementById("orientation");
        alert("横屏内容太少啦，请使用竖屏观看！");
        obj.style.display="block";
}

window.onorientationchange=function(){ 
var obj=document.getElementById("orientation");

if(window.orientation==0){
          obj.style.display="none";
        }else
        {
                alert("横屏内容太少啦，请使用竖屏观看！");
                obj.style.display="block";
        }
};
function showMoon()
{
    $("#mcover").show(); 
}
</script>
</html>


    ';

	
?>